<?php $this->load->view('header');?>

<body class="childrenBody">
    <blockquote class="layui-elem-quote news_search">
		
<!-- 		<div class="layui-inline">
		    <div class="layui-input-inline">
		    	<input type="text" name="keyword" value="" placeholder="用户名" class="layui-input search_input">
		    </div>
		    <a class="layui-btn layui-btn-custom search_btn" id="search"><i class="layui-icon">&#xe615;</i>查询</a>
		</div> -->

		<div class="layui-inline">
			<a class="layui-btn layui-btn-custom userAdd_btn"><i class="layui-icon">&#xe654;</i> 管理员</a>
		</div>
	</blockquote>

	<!-- 视图 -->
	<div class="layui-form news_list">
		<form class="layui-form">
			<table class="layui-table" lay-even="" lay-skin="nob">
			    <colgroup>
					<col width="8%">
					<col width="8%">
					<col width="10%">
					<col width="10%">
					<col width="12%">
			    </colgroup>
			    <thead>
				<tr>
					<th>账户名</th>
					<th>添加时间</th>
					<th>最后登录时间</th>
					<th>备注</th>
					<th>操作</th>
				</tr> 
			    </thead>
				<tbody class="goods_content" id="view"></tbody>
			</table>
		</form>
	</div>      

	<!-- 模板 -->
	<script id="demo" type="text/html">
	    {{#  layui.each(d.list, function(index, item){ }}
			<tr>
			  <td align="left">
			  	{{#  if(item.headimg){ }}
			  	<img src="{{item.headimg}}" style="width: 30px;height: 30px; border-radius: 100%;">
			  	{{# }else{ }}
				<img src="plugins/layui/images/user_img.png" style="width: 30px;border-radius: 100%;">
			  	{{#  } }} 
			  	&nbsp;&nbsp;{{ item.name }}
			  </td>
			  <td>{{ item.addtime }}</td>
			  <td>{{ item.last_time }}</td>
			  <td>{{ item.remarks }}</td>
			  <td>
<!-- 			    <a class="layui-btn layui-btn-mini" id="viewlog{{ item.id }}" title="查看日志">
			      <i class="layui-icon">&#xe60a;</i>日志
			    </a> -->
			    <a class="layui-btn layui-btn-warm layui-btn-mini" id="edit{{ item.id }}" title="编辑管理员">
			      <i class="layui-icon">&#xe642;</i>编辑
			    </a>
			    <a class="layui-btn layui-btn-danger layui-btn-mini" id="delete{{ item.id }}" title="删除管理员">
			      <i class="layui-icon">&#xe640;</i>删除
			    </a>
			  </td>
			</tr>
	    {{#  }); }}

	    {{#  if(d.list.length === 0){ }}
	      暂无数据
	    {{#  } }} 
	</script>

	<script type="text/javascript">
	layui.config({
		version: true
	}).use(['jquery','layer', 'laytpl', 'form'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer,
			laytpl = layui.laytpl,
			form = layui.form,
			$ = layui.jquery;


				$.get('admin.php/AdminUser/get_list', function(result) 
				{
					var data = JSON.parse(result);

					var getTpl = demo.innerHTML;
					laytpl(getTpl).render(data, function(html){
					  $('#view').html(html);
					});


					layui.each(data.list, function(index, el) 
					{
						//编辑
						$('#edit'+el.id).click(function() 
						{
							var index = layui.layer.open({
								title : "编辑用户信息",
								type : 2,
								content : "admin.php/AdminUser/add_edit_admin/"+el.id,
								cancel: function(index, layero){ 
									location.reload();						 
								}  
							})

							//改变窗口大小时，重置弹窗的高度，防止超出可视区域
							$(window).resize(function(){
								layui.layer.full(index);
							})
							layui.layer.full(index);
						});


						//查看日志
						$('#viewlog'+el.id).click(function() 
						{
							var index = layui.layer.open({
								title : "操作日志",
								type : 2,
								content : "admin.php/AdminUser/get_user_log/"+el.id,
							})

							//改变窗口大小时，重置弹窗的高度，防止超出可视区域
							$(window).resize(function(){
								layui.layer.full(index);
							})
							layui.layer.full(index);
						});


						//删除
						$('#delete'+el.id).click(function() 
						{
							layer.confirm('确定删除选中的信息？',{icon:3, title:'提示信息'},function(index){
								$.get('admin.php/AdminUser/delete_user',{id:el.id}, function(res) {
									if (res.status == 200) {
										layer.msg(res.message, {icon:1});
										location.reload();
									}
									else
									{
										layer.msg(res.message, {icon:2});
									}
								},"json");
							});
						});

						form.render(); //更新全部
					});
				});

			//添加管理员
			$('.userAdd_btn').click(function(event) 
			{
		        var index = layui.layer.open({
					title : "添加用户",
					type : 2,
					content : "admin.php/AdminUser/add_edit_admin",
					cancel: function(index, layero){ 
							location.reload();						 
					}  
				})

				//改变窗口大小时，重置弹窗的高度，防止超出可视区域
				$(window).resize(function(){
					layui.layer.full(index);
				})
				layui.layer.full(index);
			});

	});
	</script>

</body>
</html>